package com.mask.service.impl;

import com.mask.entity.UserInfoEntity;
import com.mask.mapper.UserInfoMapper;
import com.mask.model.DTO.QueryFuzzyUserInfoDTO;
import com.mask.service.UserInfoService;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author hx
 * @date 2021/10/8 9:26 上午
 */
@Service
@Slf4j
public class UserInfoServiceImpl implements UserInfoService {
    private Logger logger = LoggerFactory.getLogger(UserInfoServiceImpl.class);

    @Resource
    private UserInfoMapper userInfoMapper;

    @Override
    public UserInfoEntity selectByPrimaryKey(Long id) {
        return userInfoMapper.selectByPrimaryKey(id);
    }

    @Override
    public int insert(UserInfoEntity userInfoEntity) {
        return userInfoMapper.insert(userInfoEntity);
    }

    /**
     * 根据主键动态修改用户信息
     * @param userInfoEntity 用户实体类
     * @return 1成功,0失败
     */
    @Override
    public int updateByPrimaryKeySelective(UserInfoEntity userInfoEntity) {
        return userInfoMapper.updateByPrimaryKeySelective(userInfoEntity);
    }

    @Override
    public List<QueryFuzzyUserInfoDTO> queryFuzzyUserInfoByUsername(String keyword) {
        if (keyword == null || ("").equals(keyword)){
            log.warn("传入关键字为空值");
            return null;
        }
        return userInfoMapper.queryFuzzyUserInfoByUsername(keyword);
    }

    @Override
    public int queryNormalUserCount() {
        return userInfoMapper.queryNormalUserCount();
    }

    @Override
    public int queryFrozenUserCount() {
        return userInfoMapper.queryFrozenUserCount();
    }

    @Override
    public int queryDeletedUserCount() {
        return userInfoMapper.queryDeletedUserCount();
    }

    @Override
    public List<UserInfoEntity> queryUserInfoByState(int state) {
        return userInfoMapper.queryUserInfoByState(state);
    }

    @Override
    public UserInfoEntity queryUserInfoByUsernameAndSex(String username, int sex) {
        return userInfoMapper.queryUserInfoByUsernameAndSex(username,sex);
    }

    @Override
    public List<UserInfoEntity> queryUserInfoByIds(int[] userIds) {
        return userInfoMapper.queryUserInfoByIds(userIds);
    }
}
